﻿using System;
using System.Collections.Generic;
using Abp.Runtime.Session;
using pandx.Mulan.DataImExPorting.Excel;
using pandx.Mulan.Dto;
using pandx.Mulan.Form.FormSchemes.Dto;
using pandx.Mulan.Storage;

namespace pandx.Mulan.Form.FormSchemes.Exporting
{
    public class FormSchemeListExcelExporter:NpoiExcelExporterBase,IFormSchemeListExcelExporter
    {
        private readonly IAbpSession _abpSession;

        public FormSchemeListExcelExporter(IAbpSession abpSession, ITempFileCacheManager tempFileCacheManager) : base(
            tempFileCacheManager)
        {
            _abpSession = abpSession;
        }

        public FileDto ExportToExcel(List<FormSchemeListDto> formSchemeListDtos)
        {
            return CreateExcelPackage("表单模板_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".xlsx",
                excelPackage =>
                {
                    var sheet = excelPackage.CreateSheet("表单模板");
                    AddHeader(sheet,
                        "ID","创建时间","最后修改时间","表单模板名","表单类型","表单模板内容","表单模板描述","创建用户名","创建用户姓名"
                    );
                    AddObjects(sheet,2,formSchemeListDtos,
                        _=>_.Id,_=>_.CreationTime,_=>_.LastModificationTime,_=>_.SchemeName,_=>_.FormType==0?"用户设计":"系统内置",_=>_.SchemeContent,_=>_.Description,_=>_.CreatorUserName,_=>_.CreatorName
                    );
                    for(var i=1;i<=formSchemeListDtos.Count;i++)
                    {
                        sheet.AutoSizeColumn(i);
                    }
                });
        }
    }
}
